package com.ruike.alisurface.http;

import com.ruike.alisurface.utils.ShareKey;
import com.voodoo.lib_frame.base.BaseView;
import com.voodoo.lib_frame.httpTools.ApiTools;
import com.voodoo.lib_frame.httpTools.RequestParams;
import com.voodoo.lib_utils.ShareUtils;

import org.json.JSONException;
import org.json.JSONObject;

public class OtherApiHttp {

    static final String BASE_URL = "https://rk.shouhuojiyun.com/otherapi/haonuodayaofang/";
    // 取货码取货
    public static final String START_OUT_URL = BASE_URL + "start_out";
    // 获取取货码过期商品列表
    public static final String GET_EXPIRE_PRODUCT_LIST_URL = BASE_URL + "get_expire_product_list";
    // 取货码过期药品创建订单
    public static final String EXPIRE_CREATE_ORDER_URL = BASE_URL + "expire_create_order";
    // 上报订单出货情况
    public static final String END_ORDER_URL = BASE_URL + "end_order";

    /**
     * 取货码取货
     *
     * @param code     取货码
     * @param listener 监听回调
     */
    public static void startOut(String code, BaseView listener) {
        JSONObject params = new JSONObject();
        try {
            params.put("mch_id", ShareUtils.getInstance().getString(ShareKey.MCH_ID));
            params.put("code", code);
        } catch (JSONException e) {
        }
        new ApiTools().postJsonRequest(START_OUT_URL, params.toString(), listener);
    }

    /**
     * 获取取货码过期商品列表
     *
     * @param listener 监听回调
     */
    public static void getExpireProductList(BaseView listener) {
        RequestParams params = new RequestParams();
        params.put("mchid", ShareUtils.getInstance().getString(ShareKey.MCH_ID));
        new ApiTools().getRequest(GET_EXPIRE_PRODUCT_LIST_URL, params, listener);
    }

    /**
     * 取货码过期药品创建订单
     *
     * @param listener 监听回调
     */
    public static void expireCreateOrder(String orderId, BaseView listener) {
        RequestParams params = new RequestParams();
        params.put("mch_id", ShareUtils.getInstance().getString(ShareKey.MCH_ID));
        params.put("order_id", orderId);
        new ApiTools().getRequest(EXPIRE_CREATE_ORDER_URL, params, listener);
    }

    /**
     * 上报订单出货情况
     *
     * @param listener 监听回调
     */
    public static void endOrder(String orderId, boolean isEnd, String remark, boolean isFace, BaseView listener) {
        RequestParams params = new RequestParams();
        params.put("order_id", orderId);
        params.put("IsEnd", isEnd);
        params.put("remark", remark);
        params.put("isface", isFace);
        new ApiTools().getRequest(END_ORDER_URL, params, listener);
    }

}
